package com.xw.unification.condition;

import static com.xw.unification.constant.UnificationConstant.DEFAULT_API_VERSION_ENABLE;
import static com.xw.unification.constant.UnificationConstant.API_VERSION_ENABLE_PROPERTY_KEY;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Optional;

public class UnifiedApiVersionCondition extends UnificationCondition {

    @Override
    public boolean matchesCondition(ConditionContext context, AnnotatedTypeMetadata metadata) {
        return "true".equalsIgnoreCase(
                Optional.ofNullable(context.getEnvironment().getProperty(API_VERSION_ENABLE_PROPERTY_KEY))
                        .orElse(String.valueOf(DEFAULT_API_VERSION_ENABLE))
        );
    }
}
